<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>省钱</title>
    <script src="../utils/flexible.js"></script>
    <link rel="stylesheet" href="../css/save.css">
</head>

<body>
    <header id="header">
        <a href="index.html" class="back fl">〈</a>
        <h4>省钱控-最新优惠</h4>
        <div class="app fr">
            <a href="">
                <img src="../images/header_app.png" alt="">
            </a>
        </div>
    </header>
    <!-- 列表 -->
    <section id="product">
        <ul class="info">

        </ul>
    </section>
    <!-- 底部 -->
    <section id="footer">
        <div class="more">
            <a href="">
                更多优惠信息>>
            </a>
        </div>
        <div class="chart clearfix">
            <span class="chart_in fl">品牌排行</span>
            <span class="more fr">
            </span>
        </div>
        <div class="login">
            <div class="container">
                <div class="row">
                    <a href="">
                        <div class="col-xs-3">登入</div>
                    </a>
                    <a href="">
                        <div class="col-xs-4">注册</div>
                    </a>
                    <a href="">
                        <div class="col-xs-5">返回顶部</div>
                    </a>
                    <span></span>
                </div>
            </div>
            <div class="content_b">
                <p>
                    <a href="#">
                        手机APP下载
                    </a>
                    <a href="#">
                        万锋智慧商城手机版
                    </a> -- 掌上比价平台
                </p>
                <p>
                    chst.vip:8081/crm </p>
            </div>
        </div>
    </section>
</body>

</html>
<script src="../utils/lozyLoad.js"></script>
<script src='https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.js'></script>

<script>
    let container = document.querySelector('.info');

    function render(data, el) {
        let domStr = "";
        let li = document.createElement('li');
        data.forEach(item => {
            let regExp = /(?<=imgurl=)[^'"]*/
            let result = item.productImg2.match(regExp);
            domStr += `<li productid=${item.productId}>
            <img width="100"src=${result[0]} alt="">
            <h3>${item.productName}</h3>
            <span>${item.productComCount}</span>
            <span>${item.productFrom}</span>
            </li>`
            li.innerHTML = domStr;
        })
        el.appendChild(li);
    }

    function getData(pageid) {
        fetch(`http://chst.vip:1234/api/getmoneyctrl?pageid=${pageid}`)
            .then(body => body.json())
            .then(res => {
                console.log(res)
                render(res.result, container)
            })
    }

    getData()

    let pageid = 0;

    lazyLoad(function() {
        pageid++
        if (pageid > 14) {
            // alert('服务器没有更多的数据了')
            return
        }
        getData(pageid)
    }, 100)



    $(".back").click(function() {
        location.href = "./index.html"
    })

    let uu = document.querySelector('.info')
    uu.onclick = function(e) {
        if (e.target.localName === 'li') {
            let _this = e.target;
            let id = _this.getAttribute('productid')
            location.href = '../html/detail.html?productid=' + id
        }
    }
</script>